Skip to main content
ICT
A16 - Single Dimension Arrays
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

D. Arrays as Parameters page 6 of 10

  1. The program ArrayOps.java, provides examples of passing arrays as parameters. Notice that the final integer constant MAX = 6 is used to size the array in this program.
See Handout 16.1, Example Program - Arrays as Parameters ArrayOps.java
  1. The main method declares an array named data. The array is initialized with the values 0...5 inside the main method.

  2. The parameters of the squareList and printList methods are references to an array object. Any local reference to array list inside the squareList or printList methods is an alias for the array data inside of the main method. Notice that after the call of squareList, the values stored in array data in the main method have been permanently changed.

  3. When the rotateList method is called, the copy method of the ArrayOps class is invoked and the local array listCopy is created as a copy of the array data in the main method.

  4. The rotateList method rotates the values one cell to the right, with the last value moved to the front of the list. A call to printList is made inside the rotateList method just before leaving the method. After returning to the main method, notice that the array data is unchanged.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.